<?php

namespace App\Http\Middleware;

use Closure;
use League\Flysystem\Exception;

class SignVerify
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
    	$param = $request->except(['s']);
    	
    	// null 格式化成空字符串
		clear_null($param);
		
//		logger($param);
    	$sign = $param['sign'];
    	unset($param['sign']);
		ksort($param);
//		logger($param);
    	$param2 = [];
    	foreach($param as $k => $v){
			$param2[] = $k.'='.$v;
		}
		$param_sign = strtolower(md5(implode('&',$param2)));
		
//		dd($param,$param2,$param_sign,$sign);
//		logger('我的签名'.$param_sign);
		if($param_sign != $sign){
//			return json_error('error');
			return redirect()->route('sign_verify_failed');
		}else{
			return $next($request);
		}
    }
}
